﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using YiSha.Data.Repository;
using YiSha.Entity.QixingManage;
using YiSha.Util;
using YiSha.Util.Extension;

namespace YiSha.Service.QixingManage
{
    public class UmsMemberService : RepositoryFactory
    {
        public async Task<UmsMemberEntity> GetEntity(long id)
        {
            return await this.BaseRepository().FindEntity<UmsMemberEntity>(id);
        }

        public async Task<UmsMemberEntity> GetUserIdByEntity(long uid)
        {
            return await this.BaseRepository().FindEntity<UmsMemberEntity>(t=>t.userid== uid);
        }

        public async Task<UmsMemberEntity> GetOpenIdByEntity(string openid)
        {
            return await this.BaseRepository().FindEntity<UmsMemberEntity>(t => t.openid == openid);
        }
        #region 提交数据
        public async Task SaveForm(UmsMemberEntity entity)
        {
            if (entity.Id.IsNullOrZero())
            {
                entity.Create();
                await this.BaseRepository().Insert(entity);
            }
            else
            {

                await this.BaseRepository().Update(entity);
            }
        }

        public async Task DeleteForm(string ids)
        {
            long[] idArr = TextHelper.SplitToArray<long>(ids, ',');
            await this.BaseRepository().Delete<UmsMemberEntity>(idArr);
        }
        #endregion
    }
}
